<?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

//check auth access
if(empty($_REQUEST['accesscode']))
{
	exit("Not auth access.");
}
if(($_REQUEST['accesscode'] != "skkfdxdfdINdfd452sAsd2323dd"))
{
	exit("Not auth access.");
}
$act = !empty($_GET['act']) ? $_GET['act'] : '';

if($act == "users")
{
	$sql = "SELECT user_id,user_name,user_money,frozen_money FROM ". $GLOBALS['ecs']->table('users');
	$users = $GLOBALS['db']->getAll($sql);

	if(count($users ) == 0)
	{ 
		exit("NO_DATA");
	}
	header('Content-Type:text/xml');
	echo arrayToXml($users,"user");
}
else if($act == "accountLog")
{
	
	$sql = "SELECT log_id,user_id,user_money,frozen_money,change_time,change_desc FROM ". $GLOBALS['ecs']->table('account_log');
	if(!empty($_REQUEST['fromlogid']))
	{
		$sql .= " WHERE log_id > ".intval($_REQUEST['fromlogid']);
	}
	$logs = $GLOBALS['db']->getAll($sql);

	if(count($logs) == 0)
	{ 
		exit("NO_DATA");
	}
	header('Content-Type:text/xml');
	echo arrayToXml($logs,"log");
}

function arrayToXml($arr,$tagName)
{
	$str_xml = sprintf("<%ss>",$tagName);
	foreach($arr as $row)
	{
		$str_xml .=  sprintf("<%s>",$tagName);
		foreach(array_keys($row) as $key)
		{
			$str_xml .= sprintf("<%s>%s</%s>",$key,$row[$key],$key);
		}
		$str_xml .= sprintf("</%s>",$tagName);
	}
	$str_xml .= sprintf("</%ss>",$tagName);

	return $str_xml;
}


?>